package dfbz.Map自定义对象作为key或value;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo01 {
    public static void main(String[] args) {
        //new 一个hashmap
        HashMap<Student, String> map = new HashMap<>();//key为学生类  ，value为地址
        Student s1 = new Student("张三1", 12);
        Student s2 = new Student("张三2", 13);
        Student s3 = new Student("张三3", 14);
        Student s4 = new Student("张三4", 15);
        Student s5 = new Student("张三1", 12);
        String dz1="天河区";
        String dz2="白云区";
        String dz3="黄埔区";
        String dz4="越秀区";
        String dz5="南沙区";
        map.put(s1,dz1);
        map.put(s2,dz2);
        map.put(s3,dz3);
        map.put(s4,dz4);
        map.put(s5,dz5);//在自定义student类重写了 equlas 和hascode方法 所以默认去重、
        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            System.out.println(entry.getKey()+"---"+entry.getValue());//无序的
        }

    }
}
